<!--  设备管理 -->
<template>
  <div class="box">
    <el-row style="margin-top: 5px;">
      <el-col>
        <el-select v-model="send.name" style="width: 200px;" @change="changeName(send.name)">
          <el-option v-for="(item, index) in deviceTypeList" :key="index" :label="item" :value="item" />
        </el-select>
        <el-button size="small" type="primary" style="margin-left: 5px;" @click="searchClick">
          搜索
        </el-button>
        <!-- <el-button
          size="small"
          type="primary"
          @click="centerDialogVisibleBase = true;"
        >
          新增设备
        </el-button> -->
      </el-col>
    </el-row>
    <el-table highlight-current-row :data="devicetable" border style="width: 100%;margin-top: 10px;">
      <el-table-column type="index" align="center" />
      <el-table-column align="center" label="设备类型" prop="deviceType" />
      <el-table-column align="center" label="设备名称" prop="beaconName" />
      <el-table-column align="center" label="设备种类" prop="deviceSescondType" />
      <el-table-column align="center" label="设备位置" prop="departmentName" />
      <el-table-column align="center" label="设备编号" prop="beaconId" />
      <el-table-column align="center" label="设置半径" prop="effectiveRadius" />
      <el-table-column align="center" label="检查项目" prop="checkItem" />
      <el-table-column align="center" label="描述" prop="describtion" />
      <el-table-column align="center" label="创建日期" prop="createdAt" />
      <el-table-column align="center" min-width="40px" label="使用状态" prop="isUsed">
        <template slot-scope="scope">
          <span v-if="scope.row.isUsed == 1" style="color: limegreen;">使用</span>
          <span v-else style="color: #ff7676;">禁用</span>
        </template>
      </el-table-column>
      <el-table-column min-width="70px" label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="details(scope.row, scope.$index)">
            编辑
          </el-button>
          <el-button type="text" style="color: red;margin-left: 20px;" @click="deldaima(scope.row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加设备 -->
    <el-dialog title="新增医院设备" :visible.sync="centerDialogVisibleBase" width="50%" center style="text-align: center;"
      :before-close="closeaddbase">
      <el-form ref="addbase" :model="send" :rules="addbaserules" label-width="100px" label-position="left"
        style="width: 100%;border-bottom: 1px solid #F0F0EE;border-top: 1px solid #F0F0EE;padding: 10px 0;">
        <el-row>
          <el-col :span="12">
            <el-form-item style="width: 100%;" label="设备类型 :" prop="name">
              <el-select v-model="send.name" style="width: 80%;" @change="changeName(send.name)">
                <el-option v-for="item in equipmentType" :key="item" :label="item" :value="item" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item style="width: 100%;" label="使用状态 :" prop="isUsed">
              <el-select v-model="send.isUsed" style="width: 80%;">
                <el-option v-for="(item, index) in isUsed" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <div v-if="send.name === '筛查套件'">
          <el-form-item label="网关编号 :" prop="gatewayId">
            <el-input v-model="send.gatewayId" style="width: 80%;" />
          </el-form-item>
          <el-form-item style="width: 100%;" label="套件内容 :" prop="kitContent">
            <el-checkbox-group v-model="send.kitContent" style="display: flex;flex-wrap:wrap;">
              <el-checkbox label="血压计" />
              <el-checkbox label="血糖尿酸分析仪" />
              <el-checkbox label="血脂仪" />
              <el-checkbox label="血氧仪" />
              <el-checkbox label="穿戴式心电仪" />
              <el-checkbox label="打印机" />
            </el-checkbox-group>
          </el-form-item>
        </div>
        <div v-if="send.name === '定位信标'" style="display: flex;flex-wrap: wrap;">
          <el-form-item label="设备名称 :" prop="LocationEquipmentName">
            <el-input v-model="send.LocationEquipmentName" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="类型 :" prop="LocationType">
            <el-select v-model="send.LocationType" placeholder="">
              <el-option v-for="item in type" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备编号 :" prop="LocationEquipmentNumber">
            <el-input v-model="send.LocationEquipmentNumber" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="设备位置 :" prop="LocationPosition">
            <el-select v-model="send.LocationPosition" placeholder="">
              <el-option v-for="item in position" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="感应半径 :" prop="LocationRadius">
            <el-input v-model="send.LocationRadius" style="width: 65%;" />
            <span style="margin-left: 10px;">单位 ：米</span>
          </el-form-item>
          <el-form-item label="设备描述 :" style="width: 100%;" prop="LocationDescribe">
            <el-input v-model="send.LocationDescribe" />
          </el-form-item>
        </div>
        <div v-if="send.name === '血液检查'" style="display: flex;flex-wrap: wrap;">
          <el-form-item label="设备名称 :" prop="BloodEquipmentName">
            <el-input v-model="send.BloodEquipmentName" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="设备种类 :" prop="BloodEquipmentType">
            <el-select v-model="send.BloodEquipmentType" placeholder="">
              <el-option v-for="item in bloodTypeArr" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备位置 :" prop="BloodPosition">
            <el-select v-model="send.BloodPosition" style="width: 80%;" placeholder="">
              <el-option v-for="item in position" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item style="margin-left: 10px;" label-width="90px" label="检查项目 :" prop="BloodProject">
            <el-select v-model="send.BloodProject" placeholder="">
              <el-option v-for="item in proBloodTestject" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备描述 :" style="width: 100%;" prop="BloodDescribe">
            <el-input v-model="send.BloodDescribe" />
          </el-form-item>
        </div>
        <div v-if="send.name === '辅助检查'" style="display: flex;flex-wrap: wrap;">
          <el-form-item label="设备名称 :" prop="AdjuvantEquipmentName">
            <el-input v-model="send.AdjuvantEquipmentName" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="设备种类 :" prop="AdjuvantAuxiliaryType">
            <el-select v-model="send.AdjuvantAuxiliaryType" placeholder="">
              <el-option v-for="item in auxiliaryType" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备位置 :" prop="AdjuvantPosition">
            <el-select v-model="send.AdjuvantPosition" style="width: 80%;" placeholder="">
              <el-option v-for="item in position" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item style="margin-left: 10px;" label-width="90px" label="检查项目 :" prop="AdjuvantProject">
            <el-select v-model="send.AdjuvantProject" placeholder="">
              <el-option v-for="item in proTestject" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备Ip :" prop="gatewayIdOne">
            <el-input v-model="send.gatewayIdOne" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="设备描述 :" style="width: 100%;" prop="AdjuvantDescribe">
            <el-input v-model="send.AdjuvantDescribe" />
          </el-form-item>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" @click="handleClose('addbase')">取 消</el-button>
        <el-button size="medium" type="primary" @click="add(send, 'addbase')">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 编辑 -->
    <el-dialog v-if="centerDialogVisibleupdateBase_device" title="修改设备"
      :visible.sync="centerDialogVisibleupdateBase_device" width="50%" center style="text-align: center;"
      :before-close="closeupdatebase">
      <el-form ref="updatebase" :model="getbase" :rules="updatebaserules" label-width="100px" label-position="left"
        style="width: 100%;border-bottom: 1px solid #F0F0EE;border-top: 1px solid #F0F0EE;padding: 10px 0;">
        <el-row>
          <el-col :span="12">
            <el-form-item style="width: 100%;" label="设备类型 :" prop="deviceType">
              <el-select v-model="getbase.deviceType" disabled style="width: 80%;" filterable allow-create
                default-first-option placeholder="" @change="changeUpdateName(getbase)">
                <el-option v-for="item in equipmentType" :key="item" :label="item" :value="item" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- <el-form-item style="width: 100%;" label="使用状态 :" prop="isUsed">
              <el-select v-model="getbase.isUsed" style="width: 80%;">
                <el-option v-for="(item,index) in isUsed" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item> -->
            <el-form-item label="设备名称 :" style="width: 100%;" prop="beaconName">
              <el-input v-model="getbase.beaconName" style="width: 80%;" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <div v-if="getbase.deviceType === '筛查套件'">
          <el-form-item label="网关编号 :" prop="deviceIp">
            <el-input v-model="getbase.deviceIp" style="width: 80%;" />
          </el-form-item>
          <el-form-item style="width: 100%;" label="套件内容 :" prop="deviceSescondType">
            <el-checkbox-group v-model="getbase.deviceSescondType" style="display: flex;flex-wrap:wrap;">
              <el-checkbox label="血压计" />
              <el-checkbox label="血糖尿酸分析仪" />
              <el-checkbox label="血脂仪" />
              <el-checkbox label="血氧仪" />
              <el-checkbox label="穿戴式心电仪" />
              <el-checkbox label="打印机" />
            </el-checkbox-group>
          </el-form-item>
        </div>
        <div v-if="getbase.deviceType === '定位信标'" style="display: flex;flex-wrap: wrap;">
          <el-form-item label="设备名称 :" prop="beaconName">
            <el-input v-model="getbase.beaconName" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="类型 :" prop="deviceSescondType">
            <el-select v-model="getbase.deviceSescondType" placeholder="">
              <el-option v-for="item in type" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备编号 :" prop="beaconId">
            <el-input v-model="getbase.beaconId" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="设备位置 :" prop="departmentName">
            <el-select v-model="getbase.departmentName" placeholder="">
              <el-option v-for="item in position" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="感应半径 :" prop="effectiveRadius">
            <el-input v-model="getbase.effectiveRadius" style="width: 65%;" />
            <span style="margin-left: 10px;">单位 ：米</span>
          </el-form-item>
          <el-form-item label="设备描述 :" style="width: 100%;" prop="describtion">
            <el-input v-model="getbase.describtion" />
          </el-form-item>
        </div>
        <div v-if="getbase.deviceType === '血液检查'" style="display: flex;flex-wrap: wrap;">
          <el-form-item label="设备名称 :" prop="beaconName">
            <el-input v-model="getbase.beaconName" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="设备种类 :" prop="deviceSescondType">
            <el-select v-model="getbase.deviceSescondType" placeholder="">
              <el-option v-for="item in bloodTypeArr" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备位置 :" prop="departmentName">
            <el-select v-model="getbase.departmentName" style="width: 80%;" placeholder="">
              <el-option v-for="item in position" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item style="margin-left: 10px;" label-width="90px" label="检查项目 :" prop="checkItem">
            <el-select v-model="getbase.checkItem" placeholder="">
              <el-option v-for="item in proBloodTestject" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备描述 :" style="width: 100%;" prop="describtion">
            <el-input v-model="getbase.describtion" />
          </el-form-item>
        </div>
        <div v-if="getbase.deviceType === '辅助检查'" style="display: flex;flex-wrap: wrap;">
          <el-form-item label="设备名称 :" prop="beaconName">
            <el-input v-model="getbase.beaconName" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="设备种类 :" prop="deviceSescondType">
            <el-select v-model="getbase.deviceSescondType" placeholder="">
              <el-option v-for="item in auxiliaryType" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备位置 :" prop="departmentName">
            <el-select v-model="getbase.departmentName" style="width: 80%;" placeholder="">
              <el-option v-for="item in position" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item style="margin-left: 10px;" label-width="90px" label="检查项目 :" prop="checkItem">
            <el-select v-model="getbase.checkItem" placeholder="">
              <el-option v-for="item in proTestject" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
          <el-form-item label="设备Ip :" prop="deviceIp">
            <el-input v-model="getbase.deviceIp" style="width: 80%;" />
          </el-form-item>
          <el-form-item label="设备描述 :" style="width: 100%;" prop="describtion">
            <el-input v-model="getbase.describtion" />
          </el-form-item>
        </div> -->
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" @click="handleClose('updatebase')">取 消</el-button>
        <el-button size="medium	" type="primary" @click="updatebase(getbase, 'updatebase')">确 定</el-button>
      </span>
    </el-dialog>

    <!--删除-->
    <el-dialog title="删除设备" :visible.sync="centerDialogVisibledelete_device" width="30%" center>
      <div style="width: 100%;text-align: center;border-bottom: 1px solid #F0F0EE;border-top: 1px solid #F0F0EE;">
        <div style="padding: 50px 0px;font-size: 16px;">是否删除当前设备</div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" @click="centerDialogVisibledelete_device = false">取 消</el-button>
        <el-button size="medium" type="danger" @click="del(deviceId)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { selectCloudBeacon, getHospitalsId, queryHospitalsId, bindDepartment, delBindDepartment, hospitalIdNew } from '@/api/back-management/BG_device'
export default {
  name: 'Equipment',
  props: {
    hospitalId: {
      type: [String, Number],
      default: '37'
    },
    regionId: {
      type: [String, Number],
      default: '0'
    }
  },
  data() {
    return {
      deviceTypeList: ['全部', '会诊大屏', '心电监护仪', '腕带'],

      devicetable: [],
      // 添加设备
      centerDialogVisibleBase: false,
      equipmentType: ['筛查套件', '定位信标', '血液检查', '辅助检查'],
      type: ['CloudBeacon', '手环腕带'],
      position: [],
      bloodTypeArr: ['岚煜LS2000', 'lcare2000'],
      auxiliaryType: ['理邦监护仪IM20'],
      proBloodTestject: ['生物标志物', '凝血功能', '血常规', '肌酐', '血糖', '血脂四项', '肾功能及电解质', '其他'],
      proTestject: ['心电图', 'CT', '超声', 'MRI', 'CTA', 'MRA', 'DSA'],
      isUsed: [{
        value: '1',
        label: '使用'
      }, {
        value: '2',
        label: '禁用'
      }],
      send: {
        name: '全部',
        isUsed: '1',
        gatewayId: '',
        kitContent: [],
        LocationEquipmentName: '',
        LocationType: '',
        LocationEquipmentNumber: '',
        // LocationSystemNumber: '',
        LocationPosition: '',
        LocationRadius: '',
        LocationDescribe: '',
        BloodEquipmentName: '',
        BloodEquipmentType: '',
        BloodPosition: '',
        // BloodSystemNumber: '',
        BloodProject: '生命标志物',
        BloodDescribe: '',
        AdjuvantEquipmentName: '',
        AdjuvantAuxiliaryType: '',
        AdjuvantPosition: '',
        // AdjuvantSystemNumber : '',
        AdjuvantProject: '心电图',
        AdjuvantDescribe: ''
      },
      addbaserules: {
        kitContent: [{
          required: true,
          message: '请选择套件内容',
          trigger: 'blur'
        }],
        name: [{
          required: true,
          message: '请选择设备类型',
          trigger: 'blur'
        }],
        gatewayId: [{
          required: true,
          message: '请输入网关编号',
          trigger: 'blur'
        }],
        LocationEquipmentName: [{
          required: true,
          message: '请输入设备名称',
          trigger: 'blur'
        }],
        LocationType: [{
          required: true,
          message: '请选择类型',
          trigger: 'blur'
        }],
        LocationEquipmentNumber: [{
          required: true,
          message: '请输入设备编号',
          trigger: 'blur'
        }],
        LocationPosition: [{
          required: true,
          message: '请选择设备位置',
          trigger: 'blur'
        }],
        LocationRadius: [{
          required: true,
          message: '请输入感应半径',
          trigger: 'blur'
        }],
        LocationDescribe: [{
          required: true,
          message: '请输入设备描述',
          trigger: 'blur'
        }],
        BloodEquipmentName: [{
          required: true,
          message: '请输入设备名称',
          trigger: 'blur'
        }],
        BloodEquipmentType: [{
          required: true,
          message: '请选择设备种类',
          trigger: 'blur'
        }],
        BloodPosition: [{
          required: true,
          message: '请选择设备位置',
          trigger: 'blur'
        }],
        BloodDescribe: [{
          required: true,
          message: '请输入设备描述',
          trigger: 'blur'
        }],
        AdjuvantEquipmentName: [{
          required: true,
          message: '请输入设备名称',
          trigger: 'blur'
        }],
        AdjuvantAuxiliaryType: [{
          required: true,
          message: '请选择设备种类',
          trigger: 'blur'
        }],
        AdjuvantPosition: [{
          required: true,
          message: '请选择设备位置',
          trigger: 'blur'
        }],
        AdjuvantDescribe: [{
          required: true,
          message: '请输入设备描述',
          trigger: 'blur'
        }],
        isUsed: [{
          required: true,
          message: '请选择使用状态',
          trigger: 'blur'
        }],
        gatewayIdOne: [{
          required: true,
          message: '请输入设备Ip',
          trigger: 'blur'
        }]
      },
      // 编辑
      centerDialogVisibleupdateBase_device: false,
      getbase: {},
      updatebaserules: {
        deviceType: [{
          required: true,
          message: '请输入设备类型',
          trigger: 'blur'
        }],
        deviceIp: [{
          required: true,
          message: '请输入内容',
          trigger: 'blur'
        }],
        deviceSescondType: [{
          required: true,
          message: '请选择内容',
          trigger: 'blur'
        }],
        beaconName: [{
          required: true,
          message: '请输入设备名称',
          trigger: 'blur'
        }],
        beaconId: [{
          required: true,
          message: '请输入设备编号',
          trigger: 'blur'
        }],
        departmentName: [{
          required: true,
          message: '请输入设备位置',
          trigger: 'blur'
        }],
        describtion: [{
          required: true,
          message: '请输入设备描述',
          trigger: 'blur'
        }],
        effectiveRadius: [{
          required: true,
          message: '请输入感应半径',
          trigger: 'blur'
        }],
        gatewayIdOne: [{
          required: true,
          message: '请输入设备Ip',
          trigger: 'blur'
        }]
      },
      // 删除
      centerDialogVisibledelete_device: false,
      deviceId: ''
    }
  },
  created() {
    this.getalldevices()
  },
  methods: {
    // 点击搜索
    searchClick() {
      this.getalldevices()
    },
    getalldevices() {
      const d = {
        hospitalId: this.hospitalId,
        deviceType: this.send.name === '全部' ? null : this.send.name
      }
      selectCloudBeacon(d).then(res => {
        this.devicetable = res.data
      }).catch(err => {
        console.log(err)
      })
      hospitalIdNew({ hospitalId: this.hospitalId, pageNum: 1, pageSize: 10, token: this.$store.getters.token }).then(res => {
        const arr = []
        res.list ? res.list.forEach(item => {
          arr.push(item.name)
        }) : ""
        this.position = arr
      })
    },

    // 添加改变设备类型
    changeName(name) {
      this.send = {
        name: name,
        gatewayId: '',
        kitContent: [],
        LocationEquipmentName: '',
        LocationType: '',
        LocationEquipmentNumber: '',
        LocationPosition: '',
        LocationRadius: '',
        LocationDescribe: '',
        BloodEquipmentName: '',
        BloodEquipmentType: '',
        BloodPosition: '',
        BloodProject: '生命标志物',
        BloodDescribe: '',
        AdjuvantEquipmentName: '',
        AdjuvantAuxiliaryType: '',
        AdjuvantPosition: '',
        AdjuvantProject: '心电图',
        AdjuvantDescribe: '',
        isUsed: '1',
        gatewayIdOne: ''
      }
    },
    // 添加设备
    add(send, formname) {
      this.$refs[formname].validate((valid) => {
        if (valid) {
          let data = {}
          switch (send.name) {
            case '筛查套件':
              data = {
                deviceType: send.name,
                deviceIp: send.gatewayId,
                deviceSescondType: send.kitContent.join(','),
                hospitalId: this.hospitalId
              }
              break
            case '定位信标':
              data = {
                deviceType: send.name,
                beaconName: send.LocationEquipmentName,
                deviceSescondType: send.LocationType,
                departmentName: send.LocationPosition,
                beaconId: send.LocationEquipmentNumber,
                effectiveRadius: send.LocationRadius,
                describtion: send.LocationDescribe,
                hospitalId: this.hospitalId
              }
              break
            case '血液检查':
              data = {
                deviceType: send.name,
                beaconName: send.BloodEquipmentName,
                deviceSescondType: send.BloodEquipmentType,
                departmentName: send.BloodPosition,
                checkItem: send.BloodProject,
                describtion: send.BloodDescribe,
                hospitalId: this.hospitalId
              }
              break
            case '辅助检查':
              data = {
                deviceType: send.name,
                beaconName: send.AdjuvantEquipmentName,
                deviceSescondType: send.AdjuvantAuxiliaryType,
                departmentName: send.AdjuvantPosition,
                checkItem: send.AdjuvantProject,
                describtion: send.AdjuvantDescribe,
                hospitalId: this.hospitalId,
                deviceIp: send.gatewayIdOne
              }
              break
          }
          data.isUsed = send.isUsed
          data.userId = this.$store.getters.userId
          bindDepartment(data).then(res => {
            if (res.code === 0) {
              this.centerDialogVisibleBase = false
              this.$message({
                message: '保存成功',
                type: 'success'
              })
              this.send = {
                name: '筛查套件',
                gatewayId: '',
                kitContent: [],
                LocationEquipmentName: '',
                LocationType: '',
                LocationEquipmentNumber: '',
                LocationPosition: '',
                LocationRadius: '',
                LocationDescribe: '',
                BloodEquipmentName: '',
                BloodEquipmentType: '',
                BloodPosition: '',
                BloodProject: '生命标志物',
                BloodDescribe: '',
                AdjuvantEquipmentName: '',
                AdjuvantAuxiliaryType: '',
                AdjuvantPosition: '',
                AdjuvantProject: '心电图',
                AdjuvantDescribe: '',
                isUsed: '1',
                gatewayIdOne: ''
              }
              this.getalldevices()
            } else if (res.code === 9999) {
              this.$message.error(res.error)
              this.send = {
                name: '筛查套件',
                gatewayId: '',
                kitContent: [],
                LocationEquipmentName: '',
                LocationType: '',
                LocationEquipmentNumber: '',
                LocationPosition: '',
                LocationRadius: '',
                LocationDescribe: '',
                BloodEquipmentName: '',
                BloodEquipmentType: '',
                BloodPosition: '',
                BloodProject: '生命标志物',
                BloodDescribe: '',
                AdjuvantEquipmentName: '',
                AdjuvantAuxiliaryType: '',
                AdjuvantPosition: '',
                AdjuvantProject: '心电图',
                AdjuvantDescribe: '',
                isUsed: '1',
                gatewayIdOne: ''
              }
              this.getalldevices()
              this.centerDialogVisibleBase = false
            } else {
              this.centerDialogVisibleBase = false
              this.$message({
                message: '保存失败',
                type: 'warning'
              })
            }
          })
        } else {
          return false
        }
      })
    },
    // 综合方法
    handleClose(formname) {
      if (formname === 'updatebase') {
        this.centerDialogVisibleupdateBase_device = false
        this.getalldevices()
      } else {
        this.centerDialogVisibleBase = false
      }
    },
    closeaddbase() {
      this.$nextTick(() => {
        this.handleClose('addbase')
      })
    },
    closeupdatebase() {
      this.$nextTick(() => {
        this.handleClose('updatebase')
      })
    },

    /* 编辑 */
    details(data, index) {
      if (data.deviceType === '筛查套件') {
        if (data.deviceSescondType) data.deviceSescondType = data.deviceSescondType.split(',')
      }
      this.getbase = data
      console.log(this.getbase)
      this.centerDialogVisibleupdateBase_device = true
    },
    changeUpdateName(data) {
      const getbase = {
        deviceType: data.deviceType,
        isUsed: '1',
        deviceIp: '',
        beaconName: '',
        beaconId: '',
        departmentName: '',
        effectiveRadius: '',
        describtion: '',
        checkItem: data.checkItem,
        hospitalId: data.hospitalId,
        id: data.id
      }
      if (data.deviceType === '筛查套件') {
        getbase.deviceSescondType = []
      } else {
        getbase.deviceSescondType = ''
      }
      this.getbase = getbase
    },
    updatebase(getbaseData, formname) {
      const that = this
      that.$refs[formname].validate(valid => {
        if (valid) {
          let data = {}
          // switch (getbaseData.deviceType) {
          //   case '筛查套件':
          //     data = {
          //       deviceIp: getbaseData.deviceIp,
          //       deviceSescondType: getbaseData.deviceSescondType.join(',')
          //     }
          //     break
          //   case '定位信标' :
          //     data = {
          //       beaconName: getbaseData.beaconName,
          //       deviceSescondType: getbaseData.deviceSescondType,
          //       departmentName: getbaseData.departmentName,
          //       beaconId: getbaseData.beaconId,
          //       effectiveRadius: getbaseData.effectiveRadius,
          //       describtion: getbaseData.describtion
          //     }
          //     break
          //   case '血液检查' :
          //     data = {
          //       beaconName: getbaseData.beaconName,
          //       deviceSescondType: getbaseData.deviceSescondType,
          //       departmentName: getbaseData.departmentName,
          //       checkItem: getbaseData.checkItem,
          //       describtion: getbaseData.describtion
          //     }
          //     break
          //   case '辅助检查' :
          //     data = {
          //       beaconName: getbaseData.beaconName,
          //       deviceSescondType: getbaseData.deviceSescondType,
          //       departmentName: getbaseData.departmentName,
          //       checkItem: getbaseData.checkItem,
          //       describtion: getbaseData.describtion,
          //       deviceIp: getbaseData.deviceIp
          //     }
          //     break
          // }
          data.beaconName = getbaseData.beaconName
          data.hospitalId = getbaseData.hospitalId
          data.id = getbaseData.id
          data.deviceType = getbaseData.deviceType
          data.isUsed = getbaseData.isUsed
          data.userId = this.$store.getters.userId
          bindDepartment(data).then(res => {
            if (res.code === 0) {
              this.centerDialogVisibleupdateBase_device = false
              this.$message({
                message: '修改成功',
                type: 'success'
              })
              this.getalldevices()
              this.getbase = {}
            } else if (res.code === 9999) {
              this.repeatPrompt(res.error)
            } else {
              this.$message({
                message: '修改失败',
                type: 'warning'
              })
            }
          })
        } else {
          return false
        }
      })
    },
    // 删除设备
    deldaima(data) {
      this.deviceId = data.id
      this.centerDialogVisibledelete_device = true
    },
    // 删除
    del(deviceId) {
      const data = {
        id: deviceId
      }
      delBindDepartment(data).then(res => {
        if (res.code === 0) {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.getbase = {}
          this.getalldevices()
          this.centerDialogVisibledelete_device = false
        } else {
          this.$message({
            message: '删除失败',
            type: 'warning'
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.el-checkbox {
  width: 160px;
}

.el-form-item {
  width: 45%;
  margin: 0 10px 22px 0;
}
</style>
